package com.property.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.property.pojo.Staff;
import com.property.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.List;
import java.util.regex.Pattern;

@RequestMapping("staff")
@RestController
public class StaffController {
    @Autowired
    private StaffService staffService;
    //查询员工
    @RequestMapping("findAllStaff")
    public String findAllStaff(Integer page){
        return staffService.findAllStaff(page);
    }

    //新增/更新员工
    @RequestMapping("saveUpdateStaff")
    public String saveStaff(Staff staff){
        return staffService.updateOrSaveStaff(staff);
    }

    //删除员工
    @RequestMapping("deleteStaff")
    public String delete(Integer sId){
        int num = staffService.deleteStaff(sId);
        return JSON.toJSONString(num >0 ?"删除成功":"删除失败");
    }
    //根据id查询员工
    @RequestMapping("findBysId")
    public String findBysId(Integer sId){
        Staff staff = staffService.findBysId(sId);
        return JSON.toJSONString(staff);
    }
}
